<template>
    <view>
        <!-- pages/applyCommunity/applyCommunity.wxml -->
        <view class="body-t">
            <view class="body-container">
                <view class="body-banner">
                    <view class="body-h1">邻里共享 互帮互助</view>
                    <image src="../../static/assets/img/communitybg.png" mode="widthFix"></image>
                    <view class="body-h4">您的小区还未加入邻里共享，发起人数达到10人后，我们将和物业协商开通 ！</view>
                </view>
            </view>
            <view class="cm-title">请输入小区名称</view>
            <view class="cm-input">
                <van-field v-model="valueApply" :border="true" placeholder="请输入" />
            </view>
        </view>
        <view class="body-btn">
            <van-button type="info" data-key="item" @tap.native="handleApply($event, { key: 'item' })">我要申请开通</van-button>
        </view>
    </view>
</template>

<script>
// pages/applyCommunity/applyCommunity.js
import util from './../../utils/util.js';
import api from './../../utils/api.js';
import { Dialog } from 'vant';
export default {
    data() {
        return {
            valueApply: '' //申请小区
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    // onShareAppMessage: function () {
    // }
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */ methods: {
        //申请小区
        handleApply(e, _dataset) {
            /* ---处理dataset begin--- */
            this.datasetHandle(e, _dataset);
            /* ---处理dataset end--- */
            if (this.valueApply != '') {
                this.getcommitMyUnit();
            } else {
                uni.showToast({
                    title: '请输入关联小区名称',
                    icon: 'none'
                });
            }
        },

        //申请关联小区
        getcommitMyUnit(data) {
            const unionId = uni.getStorageSync('unionId') || '';
            util.request(api.commitMyUnit + '?userUnionId=' + unionId + '&applyUnitName=' + this.valueApply, 'get').then((res) => {
                if (res.code == 0) {
                    uni.showToast({
                        title: '申请成功',
                        icon: 'success'
                    });
                    uni.navigateTo({
                        url: '../applySuccess/applySuccess'
                    });
                } else {
                    uni.showToast({
                        title: res.msg
                    });
                }
            });
        }
    }
};
</script>
<style>
@import './applyCommunity.css';
</style>
